home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / flgzero.exe / FLGZERO.ASM < prev    next >
Assembly Source File  |  1991-09-16  |  3KB  |  69 lines

  1.         PAGE    ,132        ; 80 for narrow printers
  2.         TITLE    ZERO FLAGS    ; Set display tab to 8 characters
  3.         COMMENT    *
  4.     
  5. Given the base address of a flag word and the number of bits it contains,
  6. this function will set all the bits in the flag word to zero (Note that it works
  7. in byte increments)  The program zeros nothing if no bits are defined, allowing
  8. it to be used with a variable.  It is not designed to work with negative bit counts.
  9.  
  10. Programmed By:    A. L. Bender, M. D.
  11.         Bender Consulting
  12.         PO Box 8685
  13.         Woodcliff Lake, NJ 07675
  14.  
  15. Not copyright, freely in public domain.
  16. Not responsible for your use or misuse of this program.
  17.  
  18. This program was tested with Microsoft c 5.1.  It demonstrates how the bits
  19. are stored in a word.  The enclosed driver program shows how to call it and
  20. how to test it.  Assumes direction flag is set to FORWARD.  (An ok MSC 5.1
  21. Assumption)
  22.  
  23. The primary purpose of this program is instructional, you can hopefully learn
  24. something about MASM 5.1 Programming from this, especially how to use the
  25. higher level language interface.  See Microsoft MASM 5.1 Update.
  26.  
  27. Note: This will not execute on an 8086/88 but requires at least an 80186 or V20 
  28. You can remove the .186 statement to get it going on the 8086/88 if you need to
  29.  
  30. The masm call line needs /Dmemmodel={SMALL|MEDIUM|COMPACT|LARGE} as the case
  31. may be to write the proper code.
  32. Example:
  33. masm /Dmemmodel=SMALL /Mx flgzero,,,;  Makes a small model flgzero
  34.  
  35.  
  36. *
  37.         .186                    ; Set processor required
  38.         IFDEF        memmodel        ; Did user define it?
  39. %        .MODEL        memmodel,c        ; Use user definition
  40.         ELSE
  41.         .MODEL        LARGE, c        ;If not told otherwise, make
  42.         ENDIF
  43.         .CODE                    ;Large Model C Program
  44. flgzero        PROC        flagword:PTR BYTE, nrbits:WORD    ; Prologue
  45.         MOV        AX,nrbits        ; Get Bit count
  46.         TEST        AX,AX            ; If bits are defined (Non Degenerative Case)
  47.         JZ        @F            ; don't get out
  48.         DEC        AX            ; Make count 0...7
  49.         IF        @Cpu NE 0
  50.         SAR        AX,3            ; Divide by 8 The easy way
  51.         ELSE
  52.         MOV        CL,3            
  53.         SAR        AX,CL            ; Divide by 8 the hard way
  54.         ENDIF
  55.         XOR        CX,CX            ; Prep CX for later
  56.         INC        AX            ; Insure fraction of byte is ok
  57.         XCHG        CX,AX            ; Copy Quotient of 8 to CX And Zero To AX
  58.         PUSH        DI            ; Preserve DI from certain ruin
  59.         IF        @Datasize EQ 1        ; 
  60.         LES        DI,flagword        ; Get the base address for large data
  61.         ELSE
  62.         MOV        DI,flagword        ; for small data get the address
  63.         ENDIF
  64.         REP STOSB                ; Zero the bytes (See assumption)
  65.         POP        DI            ; Return DI to prior state
  66. @@:        RET                    ; Return to user program
  67. flgzero        ENDP                    ; Epilogue
  68.         END                    ; Epitaph
  69.